// 定时器，延时执行，防抖动
const debounce = (callback, wait) => {
    let timeoutId = null;
    return (...args) => {
        window.clearTimeout(timeoutId);
        timeoutId = window.setTimeout(() => {
            callback.apply(null, args);
        }, wait);
    };
};

// 监听页面滚动事件，页面滚动时过滤广告
window.addEventListener('scroll', debounce((event) => {
    let cards = document.getElementsByClassName("san-card");
    if(!cards || cards.length == 0){
        return
    }
    let idx = [];
    for (let i = 0; i < cards.length; i++) {
        let c = cards[i].textContent;
        if(c.indexOf("6AT") >=0
            || c.indexOf("8AT") >=0
            || c.indexOf("黄一鸣") >=0
            || c.indexOf("瞬间不香了") >=0
            || c.indexOf("突发！") >=0
            || c.indexOf("最新消息") >=0
            || c.indexOf("想不到") >=0
            || c.indexOf("竟然") >=0
        ){
            idx[idx.length] = cards[i];
            console.log(c);
        }
    }
    if(idx.length == 0){
        return;
    }
    for (let i = 0; i < idx.length; i++) {
        idx[i].remove();
    }
}, 300));

console.log("自定义广告过滤器生效了!");